package com.smarth.zhizulian.app;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.smarth.zhizulian.R;
import com.smarth.zhizulian.utils.KumaLog;
import com.smarth.zhizulian.utils.KumaToast;
import com.smarth.zhizulian.view.TitleBar;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.IUmengCallback;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;


/**
 * Created by KUMA on 2017/8/3.
 */

public class BaseActivity extends AppCompatActivity {
    protected Activity mContext;
    private InputMethodManager imm;
    protected String mClassName;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mContext = this;
        mClassName = this.getClass().getName();
        initStatusBar();
//        PushAgent.getInstance(mContext).onAppStart();
        PushAgent.getInstance(this).onAppStart();
    }

    protected void initStatusBar() {
        ImmersionBar.with(this)
                .statusBarDarkFont(true)
                .statusBarColor(R.color.white)
                .fitsSystemWindows(true)
                .init();
    }

    protected void setTitlebar(String title, boolean isShowBack) {
        TextView titlebar_title = findViewById(R.id.titlebar_title);
        ImageView titlebar_back = findViewById(R.id.titlebar_back);
        titlebar_title.setText(title);
        if (isShowBack) {
            titlebar_back.setVisibility(View.VISIBLE);
            titlebar_back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    hideKeyBoard(view);
                    finish();
                }
            });
        }
    }

    protected void setTitlebar(String title, boolean isShowBack, String right, View.OnClickListener onClickRight) {
        TextView titlebar_title = findViewById(R.id.titlebar_title);
        ImageView titlebar_back = findViewById(R.id.titlebar_back);
        titlebar_title.setText(title);
        titlebar_back.setVisibility(View.VISIBLE);
        titlebar_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                hideKeyBoard(view);
                finish();
            }
        });
        TextView titlebar_right = findViewById(R.id.titlebar_righ);
        titlebar_right.setText(right);
        titlebar_right.setVisibility(View.VISIBLE);
        titlebar_right.setOnClickListener(onClickRight);
    }
//
//    protected void setTitlebar(String title, boolean isShowBack, TitleBar.TextAction textAction) {
//        TitleBar titleBar = (TitleBar) findViewById(R.id.tb_titlebar);
//        if (isShowBack) {
//            titleBar.setLeftImageResource(R.drawable.fanhui);
//            titleBar.setLeftClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    finish();
//                }
//            });
//        }
//        titleBar.setTitle(title);
////        titleBar.setTitleSize(36);
//        titleBar.setTitleColor(R.color.app_textcolor);
//        titleBar.addAction(textAction);
//    }

//    protected void setTitlebar(String title, View.OnClickListener onClickListener) {
//        TitleBar titleBar = (TitleBar) findViewById(R.id.tb_titlebar);
//        titleBar.setLeftImageResource(R.drawable.fanhuijiantou);
//        titleBar.setLeftClickListener(onClickListener);
//        titleBar.setTitle(title);
////        titleBar.setTitleSize(36);
//        titleBar.setTitleColor(R.color.app_textcolor);
//    }


    public void showMsg(String str) {
        KumaToast.show(mContext, str);
    }

    public void hideKeyBoard(View view) {
        imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }

//    public void showKeyBoard() {
//        imm.showSoftInput(IActivity.this.getCurrentFocus(), InputMethodManager.SHOW_FORCED);
//    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}